<!--
- File:    粉丝列表.
-->
<template>
  <div class="Web_Box">
    <div
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="false"
      infinite-scroll-distance="0"
      infinite-scroll-immediate-check="false">
      <div class="bg_fff mb10" v-for="fans in fansList.data" @click="gotoBlog(fans.member_id)">
        <div class="diary">
          <ul class=" f-cb">
            <li class="imgs"><a><img :src="fans.member_avatar ? $config.imgsite + $config.avatarSrc + fans.member_avatar + '_w150': defaultAvatar"></a></li>
            <li class="pl20 w400"><a>
              <h3 class="d_tit">{{fans.member_name}}</h3>
              <p class="slh">{{fans.fans_num}}位粉丝</p>
            </a></li>
            <!--<li><a href="" class="f_close">取消关注</a></li>-->
          </ul>
        </div>
      </div>
    </div>
    <loading-more :allLoaded="fansList.allLoaded" :show="fansList.data.length > 0"></loading-more>
    <empty-data :show="fansList.allLoaded && fansList.data.length <= 0"></empty-data>
    <footer-tab></footer-tab>
  </div>
</template>

<script>

  export default{
    data() {
      return {
        memberId: this.$route.params.id,
        defaultAvatar: require('../../../assets/images/avatar.png'),
        fansList: {requested: false, loading: false, allLoaded: false, page: 1, pageSize: 10, data: []}
      }
    },
    components: {},
    created() {
      this.getFansList(this.fansList.page, this.fansList.pageSize)
    },
    methods: {
      gotoBlog(memberId) {
        this.$router.push({name: 'blog-index', query: {member: memberId}})
      },
      gotoGoodsDetail(storeId, id) {
        this.$router.push({name: 'goods-detail', params: {id: id}, query: {storeId: storeId}})
      },
      getFansList(page, pageSize) {
        this.fansList.loading = true
        this.$request.getFansList(page, pageSize, this.memberId).then(data => {
          if (data.length < this.fansList.pageSize) {
            this.fansList.allLoaded = true
          }
          this.fansList.data = [...this.fansList.data, ...data]
        }).finally(() => {
          this.fansList.requested = true
          this.fansList.loading = false
        })
      },
      loadMore() {
        if (this.fansList.loading || this.fansList.allLoaded) { // 正在加载 或 已取得全部数据
          return
        }
        setTimeout(() => {
          this.getFansList(++this.fansList.page, this.fansList.pageSize)
        }, 500)
      },
      delFans(id) {
        this.$messageBox.confirm(`你确定要删除吗?`).then(action => {
          this.$request.delFans(id).then(data => {
            this.$toast('删除收藏成功')
            for (let i = 0; i < this.fansList.data.length; i++) {
              if (this.fansList.data[i].goods_commonid == id) {
                this.fansList.data.splice(i, 1)
              }
            }
          }).catch(e => {
            this.$toast('删除收藏失败：' + e.msg)
          })
        }).catch(() => {
        })
      }
    }
  }
</script>

<style>

</style>